﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yu.Cms.Common;

namespace Yu.Cms.Web.UserCtrl.Default
{
    public partial class GuestC : BaseCtrl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string act = YuRequest.GetQueryString("act",true);
                if (act.ToLower() == "respond")
                {
                    string author = YuRequest.GetFormString("author");
                    string email = YuRequest.GetFormString("email");
                    string url = YuRequest.GetFormString("url");
                    string comment = YuRequest.GetFormString("comment");
                    if (this.AddBook(author, email, url, comment))
                    {
                        Response.Write("0");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("1");
                        Response.End();
                    }
                }
                //int PostID = YuRequest.GetQueryInt("PostID", 0);
                //this.OnStart(PostID);
            }
        }

        /// <summary>
        /// 添加评论
        /// </summary>
        protected bool AddBook(string author, string email, string url, string comment)
        {
            Yu.Cms.Model.Book mBook = new Yu.Cms.Model.Book();
            mBook.bName = author;
            mBook.bEmail = email;
            mBook.bContent = "<p>" + comment + "</p>";
            mBook.bWeb = url;
            mBook.PubTime = DateTime.Now;
            mBook.PubIp = Utils.GetRealIP();
            int rInt = 0;
            rInt = bllBook.Add(mBook);
            if (rInt != -1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}